/**************************************************************************//**
* @file     sys_uart.c
* @version  V1.00
* $Revision: 5 $
* $Date: 15/05/18 4:02p $
* @brief    NUC970 SYS UART driver source file
*
* @note
* Copyright (C) 2015 Nuvoton Technology Corp. All rights reserved.
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include "sys.h"

#define com_port     USART2

uint8_t putc_buff[4096];
uint16_t putc_site_now=0;
uint16_t putc_site_snd=0;

/*!
    \brief      putc for 
    \param[in]  none
    \param[out] none
    \retval     none
*/

int fputc(int ch, FILE *f)
{
  putc_site_now &= 0x0FFF;
  putc_buff[putc_site_now++] = ch;
    
  /*
    USART_CTL0(com_port)   |= (uint32_t)USART_CTL0_TEN;
    while (0 == (USART_STAT0(com_port) & USART_STAT0_TBE)); //waits for TX_FULL bit is clear
    
    USART_DATA(com_port) = ch;
  */
  
    /*
    if(ch == '\n')
    {
        while (0 == (USART_STAT0(com_port) & USART_STAT0_TBE)); //waits for TX_FULL bit is clear
        
        USART_DATA(com_port) = '\r';
    }
    */
    
    return ch;
}


/*!
    \brief      snd in systick
    \param[in]  none
    \param[out] none
    \retval     none
*/
void __sys_putc_scan(void)
{
    if(putc_site_now != putc_site_snd)
    {
        USART_CTL0(com_port)   |= (uint32_t)USART_CTL0_TEN;
        putc_site_snd &= 0x0FFF;
        USART_DATA(com_port)  = putc_buff[putc_site_snd++];
    }
}

/*!
    \brief      uart init
    \param[in]  none
    \param[out] none
    \retval     none
*/
void   sys_com_Initialize(void)
{
    USART_CTL0(com_port)   |= (uint32_t)USART_CTL0_TEN;
}

/*!
    \brief      printf none
    \param[in]  none
    \param[out] none
    \retval     none
*/
void __printf_none(int8_t * pcStr,...)
{

}

/*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
